package com.hspedu.service.Impl;

import com.hspedu.entity.Monster;
import com.hspedu.hspspringmvc.annotation.Service;
import com.hspedu.service.MonsterService;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

@Service
public class MonsterServiceImpl implements MonsterService {
    @Override
    public List<Monster> listMonsters() {
        ArrayList<Monster> monsters = new ArrayList<>();
        monsters.add(new Monster(100, "牛魔王", "芭蕉扇", 500));
        monsters.add(new Monster(200, "蜘蛛精", "吐口水", 200));
        return monsters;
    }

    @Override
    public List<Monster> findMonstersByName(String name) {
        ArrayList<Monster> monsters = new ArrayList<>();
        monsters.add(new Monster(100, "牛魔王", "芭蕉扇", 500));
        monsters.add(new Monster(200, "蜘蛛精", "吐口水", 200));
        monsters.add(new Monster(300, "白骨精", "吐口水~", 200));
        monsters.add(new Monster(400, "青牛怪", "吐口水~~", 200));
        //根据 name 进行一个过滤, 老韩在这里简单的模拟
        ArrayList<Monster> findmonsters = new ArrayList<>();
        for (Monster monster : monsters) {
            if (monster.getName().contains(name)) {
                findmonsters.add(monster);
            }
        }
        System.out.println(findmonsters.size());
        return findmonsters;
    }

    @Override
    public boolean login(String username) {

        if (username.equals("admin")) {
            return true;
        } else {
            return false;
        }
    }
}
